CMAKE_MINIMUM_REQUIRED(VERSION 3.10)

SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_PROCESSOR arm)

SET(CMAKE_C_COMPILER_WORKS TURE)
SET(CMAKE_CXX_COMPILER_WORKS TURE)

SET(CMAKE_C_COMPILER arm-none-eabi-gcc)
SET(CMAKE_CXX_COMPILER arm-none-eabi-g++)

PROJECT(ht32 C)

SET(CMAKE_ASM_COMPILER "arm-none-eabi-as")
SET(CMAKE_AR "arm-none-eabi-ar")
SET(CMAKE_OBJCOPY "arm-none-eabi-objcopy")
SET(CMAKE_OBJDUMP "arm-none-eabi-objdump")

INCLUDE(${PROJECT_SOURCE_DIR}/cmake/options.cmake)
INCLUDE(${PROJECT_SOURCE_DIR}/cmake/includes.cmake)

ENABLE_LANGUAGE(ASM)
SET(STARTUP_SRC ${PROJECT_SOURCE_DIR}/Startup/startup_ht32f5xxxx_gcc_01.s)
SET(CMAKE_ASM_FLAGS "${MCU_FLAGS} --defsym USE_HT32_CHIP=4")

SET(LINKER_SCRIPT ${PROJECT_SOURCE_DIR}/linker.ld)
SET(CMAKE_EXE_LINKER_FLAGS "-T${LINKER_SCRIPT} ${MCU_FLAGS} -Wl,-Map=$(PROJECT_NAME).map -Wl,--gc-sections --specs=nano.specs")

ADD_SUBDIRECTORY(./CMSIS)

#ADD_SUBDIRECTORY(./common)

ADD_SUBDIRECTORY(./HT32_Board)

#ADD_SUBDIRECTORY(./middleware)

ADD_SUBDIRECTORY(./HTSources)

AUX_SOURCE_DIRECTORY(. MAIN_SRCS)

ADD_EXECUTABLE(${PROJECT_NAME}.elf ${MAIN_SRCS} ${STARTUP_SRC})

TARGET_LINK_LIBRARIES(${PROJECT_NAME}.elf libcmsis libboard)